﻿<?php require_once('../Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE categorias SET categoria=%s WHERE id_categoria=%s",
                       GetSQLValueString($_POST['categoria'], "text"),
                       GetSQLValueString($_POST['id_categoria'], "int"));

  mysql_select_db($database_conexao, $conexao);
  $Result1 = mysql_query($updateSQL, $conexao) or die(mysql_error());

  $updateGoTo = "categoria.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_edcategoria = "-1";
if (isset($_GET['idcategoria'])) {
  $colname_edcategoria = $_GET['idcategoria'];
}
mysql_select_db($database_conexao, $conexao);
$query_edcategoria = sprintf("SELECT * FROM categorias WHERE id_categoria = %s", GetSQLValueString($colname_edcategoria, "int"));
$edcategoria = mysql_query($query_edcategoria, $conexao) or die(mysql_error());
$row_edcategoria = mysql_fetch_assoc($edcategoria);
$totalRows_edcategoria = mysql_num_rows($edcategoria);
?>
<!doctype html>

<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]>    <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]>    <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>categoria</title>
<link href="CSS ADMIN/boilerplate.css" rel="stylesheet" type="text/css">
<link href="CSS ADMIN/TEMPLAITE.css" rel="stylesheet" type="text/css">
<!-- 
Para saber mais sobre os comentários condicionais sobre as tags html na parte superior do arquivo:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

Se você estiver usando a compilação personalizada do modernizr (http://www.modernizr.com/), faça o seguinte:
* insira o link para o seu js aqui
* remova o link abaixo para o html5shiv
* adicione a classe "no-js" às tags html na parte superior
* você também pode remover o link para respond.min.js se tiver incluído o MQ Polyfill na sua compilação do modernizr 
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/respond.min.js"></script>
</head>
<body>
<div class="gridContainer clearfix">
  <div id="LayoutDiv1">
  <table width="960" align="center">
  <tr>
    <td colspan="2">
	<?php 
	include ("../temadmin/cabecalho.php");
	?>
    </td>
  </tr>
  <tr>
    <td colspan="2">
	<?php 
	include "../temadmin/menu_vertical.php";
	?>
    </td>
  </tr>
  <tr>
    <td width="250">
	<?php 
	include "../temadmin/menu.php";
	?>
    </td>
   
    
    <td width="698">
     <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <div align="center">
      <p><strong>Editar Categoria</strong></p>
      <p>&nbsp;</p>
      <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
        <table border="1" align="center">
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">Categoria:</td>
            <td><input type="text" name="categoria" value="<?php echo htmlentities($row_edcategoria['categoria'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td colspan="2" align="right" nowrap="nowrap"><input type="submit" value="Atualizar registro" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_update" value="form1" />
        <input type="hidden" name="id_categoria" value="<?php echo $row_edcategoria['id_categoria']; ?>" />
      </form>
      <p>&nbsp;</p>
    </div>
   

    </td>
  </tr>
  <tr>
    <td colspan="2">
	<?php 
	include ("../temadmin/rodape.php");
	?>
<?php
mysql_free_result($edcategoria);
?>
</td>
  </tr>
</table>
  </div>
</div>

</body>
</html>
